<!-- 群发消息 -->
<template>
  <div class="rightCenter">
    <div class="listTop">
      <div class="listTopAddBut" @click='addClick()'>
        新建消息
      </div>
      <!-- <div class="listTopInpBox">
                <div class="listTopInpIco">
                    <i class="icon font_family icon-sousuo"></i>
                </div>
                <input class="listTopInp" type="text" v-model='searchVal' oninput='searchFun' placeholder="搜索姓名/手机号 ">
            </div> -->
    </div>
    <ul class="listUl">
      <li class="listLi fristLI">
        <div class="listDiv listOne">
          消息标题
        </div>
        <div class="listDiv listTwo">
          消息内容
        </div>
        <div class="listDiv listThree">
          操作
        </div>
      </li>
      <li class="listLi dataLi" v-for="(item,index) in dataList" :class="{grayBack:index % 2 == 1}" :key='index'>
        <div class="listDiv listOne">
          {{item.title}}
        </div>
        <div class="listDiv listTwo">
          {{item.content}}
        </div>
        <div class="listDiv listThree">
          <div class="buttonBox okbut" @click='optionClick(index)'>
            删 除
          </div>
        </div>
      </li>
    </ul>
    <div class="paging">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNo" :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalVal">
      </el-pagination>
    </div>
    <!-- 删除弹框 -->
    <div class="fixedBox" v-show='checkShow'>
      <div class="popupCheckBox">
        <div class="popuplistBoxTop">
          <div class="popuplistBoxTopFont">
            确认要删除该消息吗？
          </div>
          <div class="popuplistBoxTopBut" @click='delectCancelClick()'>
            <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
          </div>
        </div>
        <div class="popupCheckButton">
          <div class="popupCheckPass" @click='delectOkClick()'>
            确 认
          </div>
          <div class="popupCheckFail" @click='delectCancelClick()'>
            取 消
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import messageRequest from "../../assets/message";
export default {
  data() {
    return {
      checkShow: false, // 删除弹框
      delectIndex: 0,
      searchVal: "", //所搜
      dataList: [],
      pageNo: 1, //页码
      pageSize: 10, //每页条数
      totalVal: 0 //总数量
    };
  },
  filters: {},
  created: function() {
    let self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "群发消息") {
          routShow = true;
        }
      }
      if (!routShow) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    } else {
      this.$router.push({
        path: "/login"
      });
      sessionStorage.clear();
      self.$message("暂无权限");
      return;
    }
    self.searchFun();
  },
  watch: {},
  mounted() {},
  methods: {
    // 消息详情
    optionClick(index) {
      this.delectIndex = index;
      this.checkShow = true;
    },
    //确认删除
    async delectOkClick() {
      let self = this;
      let params = {
        id: self.dataList[self.delectIndex].id
      };
      let res = await messageRequest.getwebmessagedelete(params);
      if (res.statusCode == 200) {
        self.$message("删除成功！");
        self.searchFun();
      } else {
        self.$message(res.statusMessage);
      }
      this.checkShow = false;
    },
    //取消删除
    delectCancelClick() {
      this.checkShow = false;
    },
    //添加
    addClick() {
      this.$router.push({
        path: "/home/message/edit"
      });
    },
    //搜索
    async searchFun() {
      let self = this;
      let params = {
        page: self.pageNo,
        pageSize: self.pageSize
      };
      let getParams = `page=${params.page}&pageSize=${params.pageSize}`;
      let res = await messageRequest.webMessageListFun(getParams);
      if (res.statusCode == 200) {
        if (res.data) {
          if (res.data.records) {
            self.dataList = res.data.records;
          }
          self.totalVal = res.data.total * 1;
        }
      } else {
        self.$message(res.statusMessage);
        self.dataList = [];
      }
    },
    //分页 - 每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchFun();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageNo = val;
      this.searchFun();
    }
  }
};
</script>
<style scoped>
.listOne {
  width: 30%;
}

.listTwo {
  width: 50%;
}

.listThree {
  width: 20%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.password {
  background: #279de2;
  padding: 0 14px;
}

.okbut {
  background: #279de2;
  margin: 0 14px;
}

.delect {
  background: #ed4a47;
}
</style>